package com.jiang.jixiang.ui;

import android.os.Bundle;
import android.text.TextUtils;


import com.jiang.jixiang.R;
import com.jiang.jixiang.api.ApiUrl;
import com.jiang.jixiang.databinding.ActivityPwdchangeBinding;
import com.jiang.jixiang.network.CommonalityModel;
import com.jiang.jixiang.network.NetWorkListener;
import com.jiang.jixiang.network.okHttpModel;
import com.ws.universal.tools.base.BaseActivity;
import com.ws.universal.tools.base.ManageActivity;
import com.ws.universal.tools.utils.ToastUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * 修改密码
 */
public class PwdChangeActivity extends BaseActivity implements NetWorkListener {
    private ActivityPwdchangeBinding binding;

    @Override
    protected void initCreate(Bundle savedInstanceState) {
        ManageActivity.putActivity(this.getClass().getSimpleName(), this);
        binding = ActivityPwdchangeBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

    }

    @Override
    protected void initView() {
        binding.inTitle.titleTextTv.setText(R.string.change_password);
        binding.inTitle.titleLeftBtn.setOnClickListener(view -> {
            finish();
        });
        binding.btnSubmit.setChangeAlphaWhenPress(true);
        binding.btnSubmit.setOnClickListener(view -> {
            hideSoftInput(binding.btnSubmit);
            if (check()) {
                subMit();
            }
        });

    }

    private void subMit() {
        Map<String, String> params = new HashMap<>();
        params.put("o_password", o_password);
        params.put("u_password", u_password);
        params.put("again_password", again_password);
        okHttpModel.post(ApiUrl.setPassword_Api, params, ApiUrl.setPassword_Api_ID, this);
    }

    private String o_password;
    private String u_password;
    private String again_password;

    private boolean check() {

        return true;
    }


    @Override
    public void onSucceed(JSONObject jsonData, int id, CommonalityModel commonality) {
        ToastUtils.showShort(commonality.getMessage());
        finish();
    }

    @Override
    public void onFail(JSONObject jsonData, int id, CommonalityModel commonality) {
        stopProgressDialog();
        ToastUtils.showShort(commonality.getMessage());
    }

    @Override
    public void onError(int id, Exception e) {
        stopProgressDialog();
        ToastUtils.showShort(e.getMessage());
    }

    @Override
    protected void FinishDesTroy() {
        ManageActivity.removeActivity(this.getClass().getSimpleName());
    }
}
